<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.LinkedList"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.PostcheckPattern"%>
<%@page import="com.shsh.safemanage.model.PostcheckContent"%>
<%@page import="com.shsh.safemanage.model.PostcheckStandard"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%
{
	
	Long postcheckID = 0l;
	Long problemID = 0l;
	String postcheckIDStr = (String)request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_ID);
	String problemIDStr = (String)request.getParameter(Constants.REQUEST_PARAMETER_PROBLEM_ID);
	try{
		postcheckID = Long.parseLong(postcheckIDStr);
	} catch (Exception e){
		
	}
	try{
		problemID = Long.parseLong(problemIDStr);
	} catch (Exception e){
		
	}
	PostCheckDao postcheckDao = DaoCreator.createPostCheckDao();
	PostCheck postcheck = postcheckDao.getPostCheck(postcheckID);
	
	long thePostcheckContentID = 0;
	List<PostcheckPattern> patternList = postcheckDao.getPostcheckPatternByPostcheckID(postcheckID);
	
	List<Object> patternArray = new ArrayList<Object>();
	for(PostcheckPattern pattern: patternList){
		int standardsInPattern = 0;
		long patternID = pattern.getId();
		List<PostcheckContent> contentList = postcheckDao.getPostcheckContentByPostcheckPatternID(patternID);
				
		List<Object> contentArray = new ArrayList<Object>();
		contentArray.add(pattern);		
		for(PostcheckContent content : contentList){
			int standardsInContent = 0;
			long contentID = content.getId();
			List<PostcheckStandard> standardList = postcheckDao.getPostcheckStandardByPostcheckContentID(contentID);
			
			standardsInContent = standardList.size();			
			content.setStandardCount(standardsInContent);
			standardsInPattern += standardsInContent;
			
			List<List<PostcheckStandard>> tmpList = new ArrayList<List<PostcheckStandard>>();

			String source = null;
			int j = 0;
			for(int i = 0; i < standardList.size(); i++){
				PostcheckStandard standard = standardList.get(i);
				String sourceIds = Util.toString(standard.getSources(), ",", "");
				if(!sourceIds.equals(source)){		
					List<PostcheckStandard> tmpList2 = new ArrayList<PostcheckStandard>();
					tmpList2.add(standard);
					
					tmpList.add(tmpList2);
					source = sourceIds;
					j++;
				} else {
					List<PostcheckStandard> tmpList2 = tmpList.get(j-1);
					tmpList2.add(standard);
				}
			}
			
			List<Object> standardArray = new ArrayList<Object>(tmpList);
			standardArray.add(0, content);
			
			contentArray.add(standardArray);
		}
		
		
		pattern.setStandardCount(standardsInPattern);
		patternArray.add(contentArray);
	}
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; <%=postcheck.getCheckName() %>岗检 &gt;&gt; 填报
</div>
<div class="tt"><%=postcheck.getCheckName()%>岗检填报</div>
<div class="content">
<table align="center" border="2" width="99%" cellpadding="0" cellspacing="1" style="table-layout: fixed;margin-bottom:5px;">
	<tr>
		<td width="75px" style="text-align:center;">
			<b>检查方式</b>
		</td>
		<td width="75px" style="text-align:center;">
			<b>工作内容</b>
		</td>
		<td style="text-align:center;">
			<b>工作标准与要求</b>
		</td>
		<td width="155px" style="text-align:center;">
			<b>工作标准来源</b>
		</td>
		<td width="55px" style="text-align:center;">
			<b>扣分标准</b>
		</td>
		<td width="55px" style="text-align:center;">
			<b>检查频次</b>
		</td>		
	</tr>
<%
for (int k=0;k < patternArray.size(); k++) {
	List<Object> tmpContentArray = (List<Object>)patternArray.get(k);
	
	PostcheckPattern pattern = (PostcheckPattern)tmpContentArray.get(0);
	boolean patternDisplayed = false;
	
	for (int j=1; j<tmpContentArray.size(); j++){
		List<Object> tmpStandardArray = (List<Object>)tmpContentArray.get(j);
		PostcheckContent content = (PostcheckContent)tmpStandardArray.get(0);
		boolean contentDisplayed = false;
	
		for (int m=1; m < tmpStandardArray.size(); m++) {
			List<PostcheckStandard> tmpList2 = (List<PostcheckStandard>)tmpStandardArray.get(m);
			
			boolean sourceDisplayed = false;
			for (int i=0; i<tmpList2.size(); i++){
				PostcheckStandard standard = tmpList2.get(i);					
%>
	<tr>	
		<%
		if(!patternDisplayed){
		%>
		<td rowspan="<%=pattern.getStandardCount()%>" style="padding-left:3px;">
			<%=pattern.getPattern() %>
		</td>
		<%
			patternDisplayed = true;
		} %>
		<%
		if(!contentDisplayed){
		%>
		<td rowspan="<%=content.getStandardCount()%>" style="padding-left:3px;">
			<%=content.getContent() %>
		</td>
		<%
			contentDisplayed = true;
		} %>
		<td style="text-align:left;padding-left:3px;line-height:150%;" class="td3">
			<a href="javascript:" onclick="openConvertProblem(<%=standard.getId()%>)"><%=standard.getStandard() %></a>
		</td>
		<%if (!sourceDisplayed) {%>
		<td rowspan="<%=tmpList2.size()%>" style="text-align:center;">
			<%=Util.toString(standard.getSourceNames(), "<br/>", "") %>
		</td>
		<%
			sourceDisplayed = true;
		}
		%>
		<td style="padding-left:3px;text-align:center;">
			<%=standard.getGradeStandard() %>
		</td>
		<td style="padding-left:3px;">
			<%=standard.getCheckFrequency() %>
		</td>
	</tr>
<%
			}
		}
	}
}
%>
</table>
<table width="100%">
<tr>
<td align="center" style="text-align:center;">
<input type="button" id="btnBack" onclick="goBack()" style="float:center;" value="返回"></input>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
function goBack(){
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/problems_tobe_converted.jsp', 
			'mainContentDiv', 
			{
				postcheckID: <%=postcheck.getId()%>
			}
	);
}

function openConvertProblem(postcheckStandardID) {
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/convert_problem.jsp', 
			'mainContentDiv', 
			{
				id: <%=problemID%>,
				postcheckStandardID: postcheckStandardID 
			}, 
			true
		);
}
</script>
<%
}
%>